
    <div class="layui-form-item">
        <label class="layui-form-label">计价方式</label>
        <div class="layui-input-block">
            <input type="radio" name="type" value="0" title="按件" {if !$info || $info['type'] == 0}checked{/if} lay-filter="typeradio" />
            <input type="radio" name="type" value="1" title="按重量" {if $info && $info['type'] == 1}checked{/if} lay-filter="typeradio" />
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">区域及价格</label>
        <div class="layui-input-inline" style="width:auto">
            <table class="layui-table"  id="config_list">
                <thead>
                <tr class="unit_tr" {if $info && $info['type'] == 1}style="display: none"{/if} >
                    <th>配送区域</th>
                    <th>首件(件)</th>
                    <th>运费(元)</th>
                    <th>续件(件)</th>
                    <th>运费(元)</th>
                    <th>操作</th>
                </tr>
                <tr class="weight_tr" {if !$info || $info['type'] == 0}style="display: none"{/if} >
                    <th>配送区域</th>
                    <th>首重(KG)</th>
                    <th>运费(元)</th>
                    <th>续重(KG)</th>
                    <th>运费(元)</th>
                    <th>操作</th>
                </tr>
                </thead>
                {foreach $config_arr as $config}
                <tr>
                    <td>
                        <input data-ids="{$config['area_ids']}" class="layui-input select_area" readonly name="" value="{$config['area_names']}" type="text" />
                        <input name="area_ids[]" class="area_ids" value="{$config['area_ids']}" type="hidden" />
                    </td>
                    <td>
                        <input name="first_unit[]" value="{$config.first_unit}" class="layui-input" onpaste="this.value=this.value.replace(/[^\d.]/g,'')" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')" type="text">
                    </td>
                    <td>
                        <input name="first_money[]" value="{$config.first_money}" class="layui-input" type="text">
                    </td>
                    <td>
                        <input name="continue_unit[]" value="{$config.continue_unit}" class="layui-input"  onpaste="this.value=this.value.replace(/[^\d.]/g,'')" onkeyup="this.value=this.value.replace(/[^\d.]/g,'')" type="text">
                    </td>
                    <td>
                        <input name="continue_money[]" value="{$config.continue_money}" class="layui-input" type="text">
                    </td>
                    <td>
                        <if condition="$key eq 0">
                            <a href="javascript:void(0)" onclick="new_config()" class="layui-btn">新增自定义区域</a>
                        <else />
                            <a class="layui-btn red" onclick="$(this).parent().parent().remove();"><i class="fa fa-trash-o"></i>删除</a>
                        </if>
                    </td>
                </tr>
                {/foreach}
            </table>
        </div>
    </div>
    <div id="ID-transfer-demo-value"></div>
<!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
<script>
    layui.use(['form', 'laydate', 'util'], function(){
        var form = layui.form;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var util = layui.util;

        // 自定义验证规则
        form.verify({
            pass: [
                /^[\S]{6,12}$/,
                '密码必须6到12位，且不能出现空格'
            ]
        });

        // 提交事件
        form.on('submit(demo1)', function(data){
            var index = layer.load();
            layer.close(index);

            var field = data.field; // 获取表单字段值
            $.ajax({
                type: "POST",
                url: "{:url('save')}",
                data: field,
                success: function(res){
                    console.log(res);
                    if(res.status){
                        layer.msg('提交成功');
                    }else{
                        layer.msg(res.msg);
                    }
                    setTimeout(function(){
                        parent.layer.closeAll();
                        parent.tableIns.reload()
                    },1000)
                }
            });
            return false; // 阻止默认 form 跳转
        });

        // 日期
        laydate.render({
            elem: '#date'
        });


    });
    //$('#config_list .select_area').click(function (){
    $(document).on('click','.select_area',function (){
        $('.select_area').removeClass('select_area_focus');
        $(this).addClass('select_area_focus');
        var check_ids = $(this).attr('data-ids');
        console.log(check_ids);
        var url = "/admin/Freight/area?area_ids=" + check_ids;
        console.log(url);
        layer.open({
            type: 2,
            title: '选择地区',
            shadeClose: true,
            shade: 0.2,
            area: ['600px', '600px'],
            content: url
        });
    })
    function select_area_old(){
        $(this).removeClass('select_area_focus');
        $(this).addClass('select_area_focus');
        var url = "/index.php?m=admin&c=Freight&a=area";
        layer.open({
            type: 2,
            title: '选择地区',
            shadeClose: true,
            shade: 0.2,
            area: ['420px', '400px'],
            content: url
        });
    }
    function new_config(){
        var html =  '<tr>' +
            ' <td> <input onclick="select_area()" class="layui-input select_area" readonly name="" value="" type="text"> <input name="area_ids[]" class="area_ids" value="" type="hidden"> </td>' +
            ' <td> ' +
            '<input class="layui-input" name="first_unit[]" value="" onpaste="this.value=this.value.replace(/[^\\d.]/g,\'\')" onkeyup="this.value=this.value.replace(/[^\\d.]/g,\'\')" type="text"> ' +
            '</td> ' +
            '<td> <input class="layui-input" name="first_money[]" value="" type="text"></td> ' +
            '<td> ' +
            '<input class="layui-input" name="continue_unit[]" value="" onpaste="this.value=this.value.replace(/[^\\d.]/g,\'\')" onkeyup="this.value=this.value.replace(/[^\\d.]/g,\'\')" type="text"> ' +
            '</td> ' +
            '<td><input class="layui-input" name="continue_money[]" value="" type="text"></td> ' +
            '<td>' +
            '<a class="layui-btn red" onclick="$(this).parent().parent().remove();"><i class="fa fa-trash-o"></i>删除</a> ' +
            '</td> ' +
            '</tr>';
        $('#config_list').append(html);
    }
    layui.form.on('radio(typeradio)', function(data){
        // console.log(data.elem.name);
        if(data.value == '0'){
            $(".weight_tr").hide();
            $(".unit_tr").show();
        }else{
            $(".unit_tr").hide();
            $(".weight_tr").show();
        }
    })
</script>
